package es.cea.chat;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class ServletMensajesGlobales
 */
@WebServlet("/ServletMensajesGlobales")
public class ServletMensajesGlobales extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletMensajesGlobales() {
        super();
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession sesion = request.getSession(); 
		ServletContext contexto = sesion.getServletContext();
		List<Mensaje> lista = (List<Mensaje>) contexto.getAttribute("Chat");
		
		PrintWriter pw= response.getWriter();
		pw.print("<html><head></head><body><p style='text-align:center'>");	
		pw.println("<font color='blue' align='centre'>");
				
		for(int i=lista.size()-1; i>=0; i--){
			if(lista.get(i).toString()!=null)
				pw.println(lista.get(i).toString()+"<br>");
			
		}
		
		pw.println("</font>");
		pw.println("<a href='ServletChat'>Volver</a>");		
		pw.println("</p></body></html>");
    	pw.close();
	}

	
}
